import type { PluginCreator, Rule, Root } from 'postcss';

const excludedRules = ['*', 'html', 'body', '#ui-app'];

interface Options { }

const postcssUI2wx: PluginCreator<Options> = (options = {}) => {
  return {
    postcssPlugin: 'postcss-ui2wx',
    process(root: Root) {
      root.walkRules((rule: Rule) => {
        const isExclude = excludedRules.some(item => rule.selector.includes(item))

        if (isExclude) {
          rule.remove();
        }
      });
    }
  }
}

// 为插件添加元数据，这是 PostCSS 要求的
postcssUI2wx.postcss = true;

// 导出插件
export { postcssUI2wx };